package com.example.demo2.controller;

import com.example.demo2.entity.*;
import com.example.demo2.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class RegulationController {

    @Autowired
    ComparisonMapper comparisonMapper;
    @Autowired
    ProjectMapper projectMapper;
    @Autowired
    StandardMapper standardMapper;

    @GetMapping("/findComparisonByUID")
    public List<Comparison> findComparisonByUID(HttpSession session) {
        Integer uID = (Integer) session.getAttribute("uID");
        List<Comparison> comparisons=comparisonMapper.findComparisonByUID(uID);
        for(Comparison comparison:comparisons){
            Integer pjId=comparison.getPjId();
            Project project=projectMapper.findProjectByPjId(pjId);
            if(project!=null){
                comparison.setPjName(project.getPjName());
                Standard standard=standardMapper.findStandardByStaId(project.getStaId());
                comparison.setStaName(standard.getStaName());
            }
        }
        return comparisons;
    }
}
